package com.sxf.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.sxf.controller.formbean.CommentVO;
import com.sxf.dao.CommentDAO;
import com.sxf.domain.Comment;
import com.sxf.domain.CommentMeta;
import com.sxf.mybatis.page.Pagination;
import com.sxf.querybean.CommentQuery;
import com.sxf.service.CommentService;


@Service
public class CommentServiceImpl implements CommentService {
	@Resource
	private CommentDAO dao;

	@Override
	public Pagination<CommentVO> queryPage(CommentQuery query) {
		return dao.queryPage(query);
	}

	@Override
	public List<CommentVO> queryList(CommentQuery query) {
		return dao.queryList(query);
	}

	@Override
	public CommentVO queryOne(CommentQuery query) {
		return dao.queryOne(query);
	}

	public Map<Long, CommentVO> queryListComment(CommentQuery query) {
		Map<Long, CommentVO> map = new HashMap<Long, CommentVO>();
		List<CommentVO> commentList = queryList(query);
		if (commentList != null && !commentList.isEmpty()) {
			for (CommentVO comment : commentList) {
				if (comment.getParent() > 0) {
					for (CommentVO comment2 : commentList) {
						if (comment2.getId().longValue() == comment.getParent()) {
							comment2.getSubCommentList().add(comment);
						}
					}
				}
			}
			for (CommentVO comment : commentList) {
				if (comment.getParent() == 0) {
					map.put(comment.getId(), comment);
				}
			}
		}
		commentList = null;
		return map;
	}

	@Override
	public Map<String, Integer> queryStatistic() {
		return dao.queryStatistic();
	}

	@Override
	public long queryNumber(CommentQuery query) {
		return dao.queryNumber(query);
	}

	@Override
	public int insert(Comment comment) {
		return dao.insert(comment);
	}

	@Override
	public int update(Comment comment) {
		return dao.update(comment);
	}

	@Override
	public int delete(Comment comment) {
		return dao.delete(comment);
	}

	@Override
	public long insertCommentMeta(CommentMeta commentMeta) {
		return dao.insertCommentMeta(commentMeta);
	}

	@Override
	public int updateCommentMeta(CommentMeta commentMeta) {
		return dao.updateCommentMeta(commentMeta);
	}

	@Override
	public int deleteCommentMeta(CommentMeta commentMeta) {
		return dao.deleteCommentMeta(commentMeta);
	}

	public void setDao(CommentDAO dao) {
		this.dao = dao;
	}

}
